﻿using System.Data.OleDb;

namespace com.fukefu.sql
{
    public class AccessOperate
    {
        OleDbConnection conn = null;
        OleDbDataReader re;
        //初始化
        public AccessOperate(string path)
        {
            //查询连接
            conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path);
            conn.Open();
        }
        //查询
        public OleDbDataReader Query(string sql)
        {
            return new OleDbCommand(sql, conn).ExecuteReader();
        }
        //返回结果条数
        public int ResultRows(OleDbDataReader re)
        {
            return re.RecordsAffected;
        }
        //获取查询数量 
        public int GetQueryNum(string cmd)
        {
            int size = 0;
            re = Query(cmd);
            if (re.Read())
            {
                int.TryParse(re[0].ToString(), out size);
            }
            re.Close();
            return size;
        }
        //插入
        public int Update(string sql)
        {
            return new OleDbCommand(sql, conn).ExecuteNonQuery();
        }
        //关闭
        public void Close()
        {
            conn.Close();
        }
    }
}
